import { getAreaObj } from '@/utils/util'
// const configToSearch = (colunm) =>{
// 	let list = []
// 	if(colunm){
// 		colunm.forEach(el => {
// 			if(el.type!='upload'){
// 				el.span = 24
// 				el.rules = []
// 				list.push(el)
// 			}
// 		})
// 	}
// 	return list
// }
const tableConfig = {
	stripe: true,
	border: true,
	maxHeight: '80vh',
	columns: [
		{ label: '所属区域', prop: 'areas_name' },
		{ label: '机构名称', prop: 'orgHomeName' },
		{label:'评价分数',prop:''},
		{label:'异常行为',prop:''},
		{
			label: '统一社会信用代码',
			prop: 'creditCode',
		},
		{ label: '联系人', prop: 'contactUserName' },
		{ label: '联系方式', prop: 'contactUserPhone' },
		{
			label: '运营状态',
			prop: 'operateStatus',
			changeField: true,
			type: 'remoteSelect',
			code: 'ORG_OPERATE_STATUS',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
		{
			label: '操作',
			prop: 'menu',
			fixed: 'right',
		},
	],
}

const searchConfig = {
	inline: true,
	showBtn: true,
	labelPosition: 'left',
	column: [
		{
			label: '信用代码',
			prop: 'creditCode',
			type: 'input',
			span: 8,
		},
		{
			label: '机构名称',
			prop: 'organizationName',
			type: 'input',
			span: 8,
		},
		{
			label: '联系人',
			prop: 'burdenUserName',
			type: 'input',
			span: 8,
		},
		{
			label: '所属地区',
			prop: 'areas',
			type: 'AplidAreaSelect',
			span: 8,
		},
		{
			label: '联系方式',
			prop: 'burdenUserPhone',
			type: 'input',
			span: 8,
		},
		{
			label: '运营状态',
			prop: 'operateStatus',
			changeField: true,
			type: 'remoteSelect',
			code: 'ORG_OPERATE_STATUS',
			api: 'getDictItemList',
			filterKey: 'value',
			multiple: false,
			span: 8,
		},
	],
}

export const baseConfig = {
	pageName: '养老服务组织管理(社区居家)',
	dictcodes: ['COMMON_FLAG', 'ORG_OPERATE_STATUS', 'ORG_LEVEL', 'LEGAL_PROPERTY', 'REGISTER_TYPE', 'ID_CARD_TYPE', 'DEPUTY_TYPE', 'LEGAL_PROPERTY'],
	rowKey: 'id',
	addLabel: '采集数据',
	tipLabel: 'orgHomeName',
	// needPigeonhole:true, // 是否显示顶部关于归档的部分
	exportMqTopic: '/ning/export/',
	api: {
		index: 'dpServiceOrgHome_page',
		add: 'dpServiceOrgHome_gather',
		edit: 'dpServiceOrgHome_edit',
		delete: 'dpServiceOrgHome_del',
		export: 'dpServiceOrgHome_export',
	},
	auth: {
		index: 'view_dpServiceOrgHome_page',
		add: 'view_dpServiceOrgHome_gather',
		edit: 'view_dpServiceOrgHome_edit',
		delete: 'view_dpServiceOrgHome_del',
		mulitSet: 'mulitSet',
		import: 'view_dpServiceOrgHome_import',
		export: 'view_dpServiceOrgHome_export',
	},
	paramsObj: {
		code: 3035,
	},
	menuBtn: [
		{
			icon: 'editor',
			label: '查看档案',
			type: 'primary',
			operate: 'Archives',
			auth: 'sys_role_edit',
			text: true,
			show: true,
		},
	],
	saveFormate: async (form) => {
		return new Promise((resolve, reject) => {
			resolve(form)
		})
	},
	dialogConfig: {
		width: '90%',
		// fullscreen: true
	},
	detailConfig: {
		customeHeader: {
			type: 'CardOne',
			title: 'orgHomeName',
			avatar: 'orgHomeLogo',
			tipList: [{ prop: 'operateStatusLabel', type: 'tip-success', label: '运营状态' }],
			tagList: [
				{ prop: 'organizationEvaluateScore', value: '未评', custome: 'tag', type: 'success', label: '评价分' },
				{ prop: 'creditCode', type: 'success', label: '统一社会信用代码：' },
			],
			menuBtn: [
				{
					icon: 'delete',
					label: '删除服务组织',
					type: 'danger',
					operate: 'delete',
          hide:'dataStatus!==0',
					auth: 'view_dpServiceOrgHome_del',
					text: false,
					show: true,
					plain: true,
				},
			],
		},
	},
	searchConfig,
	beforeOnLoadFormate: async (params) => {
		const areasObj: any = getAreaObj(params.areas, '')
		const regionObj: any = getAreaObj(params.region, 'now')
		const regionNameObj: any = getAreaObj(params.region_name, 'now')
		console.log(regionObj)
		return Promise.resolve({
			...params,
			...areasObj,
			...regionObj,
			...regionNameObj,
			areas: undefined,
			region: undefined,
			region_name: undefined,
		})
	},
	onLoadFormate: async (arr) => {
		const tableData = arr.map((item) => {
			const areasObj: any = getAreaObj(item, '', 'set')
			const regionObj: any = getAreaObj(item, 'now', 'set')
			return {
				...item,
				areas_name: areasObj.names,
				region_name: regionObj.names,
			}
		})
		return Promise.resolve(Object.freeze(tableData))
	},
	tableConfig,
}